import { NgModule } from '@angular/core';
import { RouterModule, Routes, Router, NavigationEnd } from '@angular/router';

import { IndexComponent } from './index/index.component';
import { RechargeComponent } from './recharge/recharge.component';
import { AuthGuard } from './auth/auth.guard';
import { IndexHomeComponent } from './index/home/index.component';
import { LoginComponent } from './page/login/index.component';
import { RegisterComponent } from './page/register/index.component';
import { UserCenterComponent } from './userCenter/userCenter';
import { OrderDetailComponent } from './userCenter/orderDetail';
import { AgencyComponent } from './index/AGENCY/index.component';
import { OrderComponent } from './index/order/index.component';
import { SecurityComponent } from './userCenter/security';
import { UpdatePwdComponent } from './userCenter/updatePwd';
import { WithdrawComponent } from './userCenter/withdraw';
import { GuideComponent } from './index/GUIDE/index.component';
import { RechargeSuccessComponent } from './recharge/rechargeSuccess';
import { UserInfoActivate } from './core/canActivate/userInfoActivate';
import { IndexActivate } from './core/canActivate/indexActivate';
import { GuideDetailActivate } from './core/canActivate/guideDetailActivate';
import { AgencyDetailActivate } from './core/canActivate/agencyDetailActivate';
import { GzComponent } from './page/gz/index.component';
import { UserDelComponent } from './userCenter/userDetail';

const routes: Routes = [
	{
		path: '',
		component: IndexComponent,
		children: [
			{
				path: '',
				component: IndexHomeComponent,
				resolve: {
					list: IndexActivate,
				},
			},
			{
				path: 'indexMy',
				component: UserCenterComponent,
				resolve: {
					userDel: UserInfoActivate,
				},
			},
		],
	},
	{ path: 'login', component: LoginComponent, canActivate: [AuthGuard] },
	{ path: 'register', component: RegisterComponent },
	{ path: 'agency', component: AgencyComponent,
		resolve: {
			agency: AgencyDetailActivate
		}
	},
	{
		path: 'guide',
		component: GuideComponent,
		resolve: {
			detail: GuideDetailActivate,
		},
	},
	{ path: 'order', component: OrderComponent },
	{ path: 'recharge', component: RechargeComponent },
	{ path: 'rechargeSuccess', component: RechargeSuccessComponent },
	// { path: 'feedback', component: FeedbackComponent, canActivate: [AuthGuard] },
	// { path: 'staticpages', loadChildren: () => import('./staticpages/staticpages.module').then(m => m.StaticpagesModule) }
	{ path: 'orderDetail', component: OrderDetailComponent },
	{ path: 'security', component: SecurityComponent },
	{ path: 'updatePwd/:type', component: UpdatePwdComponent },
	{ path: 'withdraw', component: WithdrawComponent },
	{ path: 'gz', component: GzComponent },
	{ path: 'userDel', component: UserDelComponent },
];

@NgModule({
	exports: [RouterModule],
	imports: [RouterModule.forRoot(routes)],
	providers: [AuthGuard, UserInfoActivate, IndexActivate, GuideDetailActivate, AgencyDetailActivate],
	declarations: [],
})
export class AppRoutingModule {

	constructor(
        private router: Router
	) {
		this.router.events
		  .subscribe((event) => {
			  if(event instanceof NavigationEnd){
				window.scrollTo({top:0});
			}
		  });
	}

}
